﻿
namespace UniLua
{
	internal class LuaDebugLib
	{
		public const string LIB_NAME = "debug";

		public static int OpenLib( ILuaState lua )
		{
			NameFuncPair[] define = new NameFuncPair[]
			{
				new NameFuncPair( "traceback", 	DBG_Traceback	),
                new NameFuncPair( "info", 	DBG_Info),
                new NameFuncPair( "err", 	DBG_Error),
			};

			lua.L_NewLib( define );
			return 1;
		}

		private static int DBG_Traceback( ILuaState lua )
		{
            lua.L_Traceback(lua, "traceback", 0);
            lua.L_ToString(-1);
            return 1;
        }

        private static int DBG_Info(ILuaState lua)
        {
            UniLua.Tools.ULDebug.Log(lua.L_ToString(-1));
            return 1;
        }

        private static int DBG_Error(ILuaState lua)
        {
            UniLua.Tools.ULDebug.LogError(lua.L_ToString(-1));
            return 1;
        }
	}
}

